<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/30/0030
 * Time: 11:08
 */

namespace app\sports_admin\service;


use think\Request;
use app\exception\SystemException;
use app\sports_admin\model\System as SystemModel;
class System
{
    /**
     * 保存系统信息
     * @param $systemId 系统信息id
     * @param $name 系统名称
     * @param $describe 系统描述
     * @param $isOpen 系统时候开启
     * @param $isRegister 前台注册是否开启
     */
    public static function preservation()
    {
        $systemId = intval(input('post.system_id'));
        $name = trim(input('post.name'));
        $describe = trim(input('post.describe'));
        $isOpen = trim(input('post.is_open')) == 'on' ? 1 : 0;
        $isRegister = trim(input('post.is_register')) == 'on' ? 1 : 0;
        if(!$systemId){
            $result = SystemModel::addSystemInfo($name,$describe,$isOpen,$isRegister);
            if(!$result->id){
                throw new SystemException([
                    'msg'=>'系统信息保存失败',
                    'errorCode'=>400
                ]);
            }
        }else{
            $bool = SystemModel::updateSystemInfo($systemId,$name,$describe,$isOpen,$isRegister);
            if(!$bool){
                throw new SystemException([
                    'msg'=>'系统信息保存失败',
                    'errorCode'=>400
                ]);
            }
        }
        return $result = ['is_open'=>$isOpen];
    }
}